package com.bangdream.michelia.view.activity.lecturer;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.andview.refreshview.XRefreshView;
import com.bangdream.michelia.R;
import com.bangdream.michelia.contract.CoursesContract;
import com.bangdream.michelia.contract.TeacherContract;
import com.bangdream.michelia.entity.CommentBean;
import com.bangdream.michelia.entity.CoursesTypeBean;
import com.bangdream.michelia.entity.TeacherBean;
import com.bangdream.michelia.entity.courses.CoursesBean;
import com.bangdream.michelia.entity.courses.TeacherListBean;
import com.bangdream.michelia.presenter.CoursesPresenter;
import com.bangdream.michelia.presenter.TeacherPresenter;
import com.bangdream.michelia.presenter.base.BasePresenter;
import com.bangdream.michelia.tool.CircleImageView;
import com.bangdream.michelia.tool.FullyLinearLayoutManager;
import com.bangdream.michelia.utils.ImageLoadUtils;
import com.bangdream.michelia.utils.L;
import com.bangdream.michelia.utils.PublicResources;
import com.bangdream.michelia.view.activity.base.BaseActivity;
import com.bangdream.michelia.view.activity.base.SwipeBackActivity;
import com.bangdream.michelia.view.adapter.CurriculumItemAdapter;
import com.bangdream.michelia.view.adapter.EliteLecturerAdapter;
import com.bangdream.michelia.view.adapter.TaskCurriculumAdapter;
import com.bangdream.michelia.view.adapter.TaskExaminationAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @date on 2018/7/19 15:30
 * @email 909732184@qq.com
 * 讲师详情
 */
public class LecturerDetails extends SwipeBackActivity<CoursesContract.ICoursesView,CoursesPresenter<CoursesContract.ICoursesView>>
implements CoursesContract.ICoursesView,TeacherContract.ITeacherView{
    private XRefreshView refreshView;
    private RecyclerView recyclerView;
    //普通课程列表布局
    private CurriculumItemAdapter curriculumItemAdapter;
    private FullyLinearLayoutManager linearLayoutManager;
    private String id;
    private TeacherBean data;
    private CircleImageView ivLogo;
    private TextView tvName,tvTitle,tvCurriculumNumber,tvContent;
    private ImageView ivMedal,ivLv;
    private TeacherPresenter teacherPresenter;
    @Override
    public int getLayout() {
        return R.layout.activity_lecturer_details;
    }

    @Override
    public void findId() {
        refreshView = findViewById(R.id.refreshView);
        recyclerView = findViewById(R.id.recyclerView);
        ivLogo = findViewById(R.id.ivLogo);
        tvName = findViewById(R.id.tvName);
        ivMedal = findViewById(R.id.ivMedal);
        ivLv = findViewById(R.id.ivLv);
        tvTitle = findViewById(R.id.tvTitle);
        tvCurriculumNumber = findViewById(R.id.tvCurriculumNumber);
        tvContent = findViewById(R.id.tvContent);
    }

    @Override
    public void setListener() {

    }

    @Override
    public void logic() {
        initTitleBar(" ","讲师详情","",this);
        if(getIntent().getExtras()!=null){
            id = getIntent().getStringExtra("id");
        }
        refreshView.setPullLoadEnable(false);
        refreshView.setPullRefreshEnable(false);
        linearLayoutManager = new FullyLinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        linearLayoutManager.setScrollEnabled(false);
        recyclerView.setFocusable(false);
        recyclerView.setLayoutManager(linearLayoutManager);
        curriculumItemAdapter = new CurriculumItemAdapter(this);
        recyclerView.setAdapter(curriculumItemAdapter);
        teacherPresenter = new TeacherPresenter();
        teacherPresenter.attach(this);
        teacherPresenter.getTeacherDetails(id);
    }

    @Override
    public CoursesPresenter createPresenter() {
        return new CoursesPresenter();
    }

    @Override
    public void setCoursestList(boolean isSuccess, int page, CoursesContract.CoursesType type, List<CoursesBean> data, String stDescribe) {
        if(isSuccess){
            if(data!=null) {
                curriculumItemAdapter.setData(data);
                curriculumItemAdapter.notifyDataSetChanged();
            }
        }
    }

    @Override
    public void setCoursesDetails(boolean isSuccess, CoursesBean data, String stDescribe) {

    }

    @Override
    public void setCoursesTypeList(boolean isSuccess, List<CoursesTypeBean> data, String stDescribe) {

    }

    @Override
    public void setCommentList(boolean isSuccess, int page, List<CommentBean> data, String stDescribe) {

    }

    @Override
    public void actionComment(boolean isSuccess, String stDescribe) {

    }

    private void setViewData(TeacherBean teacherBean) {
        this.data = teacherBean;
        if(data==null) {
            return;
        }
        L.d(data.toString());
        if(teacherBean!=null) {
            ImageLoadUtils.ImageLoad(this,teacherBean.getFaceUrl(),ivLogo,-1);
            tvName.setText(data.getName()+"");
//            tvTitle.setText(Html.fromHtml(data.getTitle()+""));
            if(data.getTitle()!=null)
            tvTitle.setText(data.getTitle());
            if(data.getContent()!=null)
            tvContent.setText(Html.fromHtml(data.getContent()+""));
            tvCurriculumNumber.setText(data.getCourseCount() + "");


            Map paramsMap = new HashMap();
            List<String> teacherIdsList = new ArrayList<>();
            teacherIdsList.add(teacherBean.getId());
            String teacherIds = JSON.toJSONString(teacherIdsList);
            L.e("teacherIds"+teacherIds);
            //paramsMap.put("teacherIds", teacherIds);
            paramsMap.put("courseOrTeacherName", teacherBean.getName());
            mPresenter.getTeacherCoursesListData(1, PublicResources.PageSize,
                    paramsMap, null);
        }

    }

    @Override
    public void setTeacherList(boolean isSuccess, int page, List<TeacherBean> data, String stDescribe) {

    }

    @Override
    public void setTeacherDetails(boolean isSuccess, TeacherBean data, String stDescribe) {
        setViewData(data);
    }
}
